#include <iostream>
using namespace std;

class Figure {
public:
    virtual string getName() const = 0;
    virtual double getArea() const = 0;
};
class Rectangle:public Figure{
public:
    Rectangle(double length,double width)
    :_length(length)
    ,_width(width)
    {

    }
    string getName()const{
        return "Rectangle";
    }
    double getArea()const{
        return _length*_width;
    }
private:
    double _length;
    double _width;

};

class Circle :public Figure{
public:
    Circle(double radius)
    :_radius(radius)
    {

    }
    string getName()const{
        return "Circle";
    }
    double getArea()const{
        return _pi*(_radius*_radius);
    }
private:
    double _pi=3.1415;
    double _radius;

};

class Triangle :public Figure{
public:
    Triangle(double length,double height,double hypotenuse)
    :_length(length)
     ,_height(height)
    ,_hypotenuse(hypotenuse)
    {

    }
    string getName()const{
        return "Triangle";
    }
    double getArea()const{
        return 0.5*(_length*_height);
    }
private:
    double _length;
    double _height;
    double _hypotenuse;
};
void display(Figure & fig) {
    cout << fig.getName() 
         << "的面积是:" 
         << fig.getArea() << endl ;
}

void test() {
    Rectangle r(10, 20);
    Circle c(15);
    Triangle t(3, 4, 5);
    display(r);
    display(c);
    display(t);
}    
int main(int argc, char * argv[]){
    test();    
    return 0;
}

